<?php
/**
 * Created by PhpStorm.
 * User: C。
 * Date: 2019/8/13
 * Time: 9:04
 */
namespace app\home\controller;

use app\common\model\Member as MemberModel;
use app\common\model\Gatherreg as GatherregModel;

/**
 * 义工招募和社会活动报名控制器
 * Class Gather
 * @package app\home\controller
 */
class Gatherreg extends Base
{
    /**
     * [index  报名记录列表]
     * @param
     * @return json
     * @author [C。]
     */
    public function index()
    {
        $model = new MemberModel();
        $gmodel = new GatherregModel();
        $param = input('param.');
        $this->getPageAndSize($param);
        $map = [];
        try{
            if(!empty($param['type'])){
                $map['g.type'] = $param['type'];
            }
            if(!empty($param['id'])){
                $map['gr.comid'] = $param['id'];
            }
            if(!empty($param['gid'])){
                $map['gr.gather_id'] = $param['gid'];
            }

            $count = $gmodel->getCountes($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $gmodel->getlists($map,$this->from, $this->size,'gr.id,gr.referrer,gr.name,gr.memid,gr.name,gr.sex,gr.age,gr.animal,gr.tel,gr.remark,g.title,gr.job,gr.education,gr.addr');
            foreach($lists as &$v){
                $mem = $model->findData($v['memid'],'id','username,img');
                $http = substr($mem['img'], 0, 4);
                if ($http != 'http') {
                    $mem['img'] = config('domain_name') . $mem['img'];
                }
                $v['img'] = $mem['img'];
                $v['username'] = $mem['username'];
            }
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        return admin_json(1, '获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}